using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PowerupController : MonoBehaviour
{
    private float timeForDie = 15f;
    
    public enum PowerupType
    {
        AddLives,
        AddShield
    }
    
    public PowerupType powerup;
    
    private PlayerController player;
    private GameManager gameManager;


    private void Start()
    {
        StartCoroutine(WaitToDie());
        player = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
        gameManager = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameManager>();

    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            Destroy(this.gameObject);
            
            if (powerup == PowerupType.AddLives)
            {
                gameManager.AddLife(1);
                // spawnManager.IsLifeOnScreen = false;
            
            }

            if (powerup == PowerupType.AddShield)
            {
                player.ShieldActivated();
            }
        }
    }

    IEnumerator WaitToDie()
    {
        yield return new WaitForSeconds(timeForDie);
        Destroy(this.gameObject);
    }
}